/** 
 * File-Name:UserAction.java
 *
 * Created on 2012-3-13 下午7:14:30
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package cn.edu.pku.sei.i.web;

import java.io.File;

import neoutil.CommonAction;
import neoutil.CommonService;
import neoutil.Config;
import neoutil.FileUtils;

import org.apache.struts2.ServletActionContext;

import cn.edu.pku.sei.i.entity.Intern;
import cn.edu.pku.sei.i.service.UserManager;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2012-3-13 下午7:14:30
 */
public class UserAction extends CommonAction {
	private Intern intern;
	private File resumeFile;
	private String resumeFileContentType;
	private String resumeFileFileName;
	private String fileSavePath;

	public String login() {
		return "intern";
	}

	public String joinIntern() {
		System.out.println((intern == null) + ","
				+ (intern.getStudentNO() == null) + ","
				+ (intern.getEmail() == null) + ","
				+ (intern.getMobilePhone() == null));
		if (intern == null || intern.getStudentNO() == null
				|| intern.getEmail() == null || intern.getMobilePhone() == null) {
			return ERROR;
		}

		intern.setEnrollYear("2010");

		if (resumeFile != null) {
			String fileName = intern.getEnrollYear() + "_"
					+ intern.getStudentNO() + "_" + intern.getName()
					+ FileUtils.getExtention(getResumeFileFileName());
			FileUtils.write(Config.getResumeSavePath(), fileName,
					getArticleFile());

			intern.setResumePath(fileName);

		}

		UserManager userManager = new UserManager();

		String result = userManager.addIntern(intern);
		if (CommonService.SUCCESS.equals(result)) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public Intern getIntern() {
		return intern;
	}

	public void setIntern(Intern intern) {
		this.intern = intern;
	}

	public File getArticleFile() {
		return resumeFile;
	}

	public void setArticleFile(File articleFile) {
		this.resumeFile = articleFile;
	}

	public String getFileSavePath() {
		return ServletActionContext.getRequest().getRealPath(fileSavePath);
	}

	public void setFileSavePath(String fileSavePath) {
		this.fileSavePath = fileSavePath;
	}

	public File getResumeFile() {
		return resumeFile;
	}

	public void setResumeFile(File resumeFile) {
		this.resumeFile = resumeFile;
	}

	public String getResumeFileContentType() {
		return resumeFileContentType;
	}

	public void setResumeFileContentType(String resumeFileContentType) {
		this.resumeFileContentType = resumeFileContentType;
	}

	public String getResumeFileFileName() {
		return resumeFileFileName;
	}

	public void setResumeFileFileName(String resumeFileFileName) {
		this.resumeFileFileName = resumeFileFileName;
	}
}
